package com.cy.controller;

import com.cy.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发送消息的测试类
 */
@RestController
public class SendMsgController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 测试
     * @return
     */
    @GetMapping("/sendMsg")
    public String sendMsg(@RequestParam String msg,@RequestParam String key) {
        /**
         * 发送消息
         * 参数1 交换机名称
         * 参数2 路由key
         * 参数3 发送的消息
         */
        rabbitTemplate.convertAndSend(RabbitMQConfig.ITEM_TOPIC_EXCHANGE,key,msg);

        //返回消息
        return "发送消息成功";
    }
}
